<template>
	<view>
		<view>
			<!-- 提示信息弹窗 -->
			<uni-popup ref="message" type="message">
				<uni-popup-message :type="msgType" :message="messageText" :duration="3000"></uni-popup-message>
			</uni-popup>
		</view>
		<!-- <view class="getScanCode" @click="getScanCode">{{ btnName }}</view> -->
		<button type="primary" @click="getScanCode">{{ btnName }}</button>
	</view>
</template>

<script>
	export default {
		name: "scanCode",
		props: {
			btnName: {
				type: String,
				default: '扫码',
			},
			logId: {
				type: String,
				default: '',
			},
			parm: {
				type: Object,
				default: {}
			},
		},

		data() {
			return {
				type: 'center',
				msgType: '',
				messageText: '',
			}
		},
		methods: {
			getScanCode() {
				if (this.parm.code != "" && this.parm.value != "" && this.parm.type!=="加工中") {
					uni.scanCode({
						onlyFromCamera: true,
						scanType: ['qrCode', 'barCode', 'dataMatrix'],
						success: res => {
							if (res.errMsg == 'scanCode:ok') {
								console.log(JSON.stringify(res))
								this.$emit("getScanCode", res.result);
							} else {
								uni.showToast({
									title: '扫码失败',
									icon: "none",
									mask: true,
								})
							}
						},
						fail: err => {
							console.log(JSON.stringify(err))
						}
					})
				}else if(this.parm.type==="加工中") {
					this.prompt(`设备加工中不能中途添加工单！`, 'error')
				}else {
					if (this.parm.code === "" && this.parm.value === "") {
						this.prompt(`设备和制程类型,不能为空！`, 'error')
					} else
					if (this.parm.code === "") {
						this.prompt(`设备不能为空！`, 'error')
					} else
					if (this.parm.value === "") {
						this.prompt(`制程类型不能为空！`, 'error')
					}
				}
			},
			//提示
			prompt(messageText, msgType) {
				this.messageText = messageText;
				this.msgType = msgType;
				this.$refs.message.open();
			},
		}
	}
</script>

<style>

</style>